﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Drawing;
using System.IO;

namespace FastGraphClustering_13._12
{
    class Network 
    {
        public static int networkID=0;
       public int numOfNodes;
       public int numOfNodesKernel_new, numOfNodesKernel_old =0;
        //int[,] adjacnyMatrix;
        public Matrix adjacnyMatrix;
        public Matrix adjacnyKernel;
        //int[,] adjacnyKernel;
        ArrayList[] nodesOfNetwork;//=new ArrayList();
        //resive the name of the file as a string. create a list and read line by line to the list. every line is an element of the list
        public Network(string f)
        {
            networkID++;
            List<string> listOfNodes = new List<string>();
            int temp = 0;
            using (StreamReader r = new StreamReader(f))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    listOfNodes.Add(line);
                }
            }

            this.numOfNodes = listOfNodes[0].Length;
            
            nodesOfNetwork = new ArrayList[numOfNodes];
                  
           // adjacnyMatrix=new int[numOfNodes,numOfNodes];//i=row,j=column
            adjacnyMatrix = new Matrix(numOfNodes);


            for (int i = 0; i < numOfNodes; i++) //create all nodes
            {             
                //Node tempNode = new Node();
                nodesOfNetwork[i] = new ArrayList();
                nodesOfNetwork[i].Add(1);
            }
            
            
            for (int i=0; i < numOfNodes; i++) // create שכן
            {
                char[] ca = listOfNodes[i].ToCharArray();

                for (int j = 0; j < numOfNodes; j++)
                {
                    temp = (int)char.GetNumericValue(ca[j]);
                    adjacnyMatrix.Data[i,j] = temp;
                    if (temp == 1)
                        nodesOfNetwork[i].Add(nodesOfNetwork[j]);

                }//for

            }  //for

           // Draw_Netwok(adjacnyMatrix);
           // nodesOfNetwork.Add();
           

        }

        public void get_numOfNodes(ref int temp)
        {
            temp = numOfNodes;
        }

        public void get_numOfNodesKernel(ref int temp)
        {
            temp = numOfNodesKernel_new;
        }

        public  void get_adjacnyMatrix (ref double[,] temp)
        {
            temp= adjacnyMatrix.Data;
        }
        public void get_adjacnyKernel(ref double[,] temp)
        {
            temp = adjacnyKernel.Data;
        }
        public void get_ID(ref int temp)
        {
            temp = networkID;
        }

      

        public ArrayList[] get_nodesOfNetwork()
        {
            return nodesOfNetwork;
        }

       

       public void Calc_adjacnyKernel(int NumOfNodes_kernel,int NumOfNodes)
        {
           // numOfNodesKernel_old = NumOfNodes_kernel;
            numOfNodesKernel_new = NumOfNodes_kernel;
           

            adjacnyKernel = new Matrix(NumOfNodes_kernel);//i=row,j=column

           
            for (int i = 0; i < NumOfNodes_kernel;i++ )
            {
                for (int j = 0; j < NumOfNodes_kernel; j++)
                {

                    adjacnyKernel.Data[i, j] = adjacnyMatrix[i, j];

                }
            }


            /* 
             * int[] temp_index = new int[NumOfNodes_kernel];
             Random rand = new Random();
             for (int i = 0; i < NumOfNodes_kernel; i++) // random index of the nodes for kernel 
                 temp_index[i] = rand.Next(NumOfNodes);

          
                 for (int j = 0; j < numOfNodes; j++)
                 {
                     if (adjacnyMatrix[j, temp_index[j]] == 1)
                         nodesOfKernel[j].Add(nodesOfNetwork[j]);


                 }//for

             */






        }



       
    
    
    
    
    }
}
